<template>
    <el-container class="home-container">
        <el-aside :width="isCollapse?'64px':'200px'">
            <div class="toggle" @click="toggle">|||</div>
            <el-menu background-color="#545c64" text-color="#fff" 
            active-text-color="#ffd04b" :collapse="isCollapse" :collapse-transition="false"
            :router="true" :default-active="$route.path"
            >
                <el-submenu :index="item.id+''" v-for="item in menulist" :key="item.id">
                    <template slot="title">
                        <i class="el-icon-location"></i>
                        <span>{{item.authName}}</span>
                    </template>
                    <el-menu-item
                        :index="'/'+subitem.path"
                        v-for="subitem in item.children"
                        :key="subitem.id"
                    >
                        <template slot="title">
                            <span>{{subitem.authName}}</span>
                        </template>
                    </el-menu-item>
                </el-submenu>
            </el-menu>
        </el-aside>
        <el-container>
            <el-header height="60px" class="img-box">
                <div class>
                    <img src="../assets/img/header.jpg" alt />
                    <span>电商管理系统</span>
                </div>
                <el-button type="info" @click="logout">退出</el-button>
            </el-header>
            <el-main >
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>
<script>
export default {
    data() {
        return {
            menulist: [],
            isCollapse: false
        };
    },
    created() {
        this.getMenuList();
    },
    methods: {
        logout() {
            sessionStorage.removeItem("token");
            this.$router.push("/login");
        },
        getMenuList() {
            this.$axios.get("menus").then(res => {
                this.menulist = res.data.data;
            });
        },
        toggle(){
            this.isCollapse=!this.isCollapse
        }
    }
};
</script>
<style lang="less" scoped>
.el-header {
    background-color: #606266;
    > div {
        display: flex;
        align-items: center;
        span {
            margin-left: 10px;
        }
    }
}
.el-aside {
    background-color: #545c64;
}
.home-container {
    height: 100%;
}
.img-box {
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 20px;
}
.el-main{
    background-color: #F9F9F9;
}
.img-box img {
    width: 50px;
    height: 50px;
}
.el-menu {
    border-right: none;
}
.toggle{
    background-color: #4A5064;
    color: white;
    font-size: 20px;
    line-height: 24px;
    text-align: center;
    letter-spacing: 0.2rem;
    cursor: pointer;
}
</style>